﻿/// <reference path="//Microsoft.WinJS.1.0/js/base.js" />
/// <reference path="UI.js" />

(function () {

    var roamingSettings = Windows.Storage.ApplicationData.current.roamingSettings;
    var settingsValue = "rssSettings";
    var nav = WinJS.Navigation;

    WinJS.Namespace.define("Settings", {
        Manager: WinJS.Class.define(
            function ManagerConstructor() {
            },
            {
            },
            {
                getRoamingSettings: function () {
                    try {
                        var settings = roamingSettings.values[settingsValue];
                        var result = Settings.Manager.defaultRssGroup;

                        if (settings) {
                            result = JSON.parse(settings);
                        }

                        return result;
                    }
                    catch (e) {
                        UI.alert("Couldn't load settings!");
                    }
                },
                setRoamingSettings: function (rssGroupJson) {
                    try{
                        var settings = JSON.stringify(rssGroupJson);
                        roamingSettings.values[settingsValue] = settings;
                    }
                    catch (e) {
                        UI.alert("Couldn't save settings!");
                    }
                },
                navigateToRssSettings: function (groupInfo) {                    
                    nav.navigate("/pages/rssSettings/rssSettingsPage.html", (groupInfo || Settings.Manager.getRoamingSettings()));
                },
                defaultRssGroupOld: {
                    key: "0",
                    title: "Sportni.bg",
                    subtitle: "Известни още като спирни.бг :)",
                    backgroundImage: "http://www.sportni.bg/images/sportniLogo.png",
                    description: "Български спортен сайт!",
                    url: "http://www.sportni.bg/rss.php?c=10",
                    itemInfo: {
                        tagName: "item",
                        title: { prefix: "", tagName: "title", attributeName: "" },
                        subtitle: { prefix: "Date: ", tagName: "pubDate", attributeName: "" },
                        description: { prefix: "Author: ", tagName: "author", attributeName: "" },
                        content: { prefix: "", tagName: "description", attributeName: "" },
                        moreInfo: { tagName: "link", attributeName: "" },
                        image: { tagName: "enclosure", attributeName: "url" },
                    },
                },
                defaultRssGroup: {
                    "key": "0",
                    "title": "Uefa.com",
                    "subtitle": "UEFA official cite news",
                    "backgroundImage": "http://img.uefa.com/imgml/rssheader.gif",
                    "url": "http://www.uefa.com/rssfeed/news/rss.xml",
                    "description": "All news about European football.",
                    "itemInfo": {
                        "tagName": "item",
                        "title": { "tagName": "title", "attributeName": "", "prefix": "" },
                        "subtitle": { "tagName": "pubDate", "attributeName": "", "prefix": "Date: " },
                        "description": { "tagName": "author", "attributeName": "", "prefix": "Author: " },
                        "content": { "tagName": "description", "attributeName": "", "prefix": "" },
                        "moreInfo": { "tagName": "link", "attributeName": "" },
                        "image": { "tagName": "enclosure", "attributeName": "url" }
                    }
                },
            }),
    });

})();